// $(document).ready(function () {
//     const tokener=window.sessionStorage.getItem("token");
//     if(!tokener){
//         window.location.href="../public/login.html"
//     }
// })

function getBoxList() {
    let boxList = {};
    $.ajax({
        async: false,
        type: "get",//type可以为post也可以为get
        url: "http://localhost:3000/",
        dataType: "json",//这里要注意如果后台返回的数据不是json格式，那么就会进入到error:function(data){}中
        success: function (data) {
            // console.log(data)
            // boxList=data;
            boxList = data
            // alert(data)
        },
        error: function (data) {
        }
    });
    return boxList;
}

let data = getBoxList();
// console.log(boxList);


// console.log(supportList)

let btn = document.getElementsByClassName("btn");
btn[0].style.backgroundColor = "#FE6C00";

// 就业互动--------------------------------------
document.getElementsByClassName('box2')[0].innerHTML = `
               <div class="boxbar">
                     <span class="boxbarLeft">就业互动</span>
                     <span class="boxbarRight">更多>></span>
                </div>
                <div id="list"></div>

`;

function getListItem(data) {
    let listItem = '';
    data.forEach(function (item, index) {
        // console.log(item);
        if (index < 4) {
            listItem += `
                        <div class="more" >
                            <div class="list">
                                <img src="${item.imgSrc}" >
                            </div>
                            <div class="listContent">
                                ${item.content}
                            </div>
                        </div>
    `
        }
    });
    return listItem;
}

document.getElementById('list').innerHTML = getListItem(data.data);


// 轮播图--------------------------------------


document.getElementsByClassName('box1')[0].innerHTML = `
<div id="banner">
<div class="prev"></div>
<div class="next"></div>
<img src="${data.RotationImg.imgSrc1}" class="RotationImg " id="imgSrc1">
<img src="${data.RotationImg.imgSrc2}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc3}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc4}" class="RotationImg " >
<img src="${data.RotationImg.imgSrc5}" class="RotationImg " >
</div>
    <div class="box1Rotation" id="box1Rotation">
    
    </div>
`;
let imgSrc1 = document.getElementById("imgSrc1");
imgSrc1.onclick = () => {
    window.location.href = "../public/detail.html"
}
// 轮播图----------------------------------------
let num = 0,
    timer = null,
    pics = document.getElementById('banner').getElementsByTagName('img'),
    dots = document.getElementById('box1Rotation').getElementsByTagName('div'),
    link = document.getElementsByClassName("RotationImg");
// link[0].onclick="location=http://localhost:63342/shangxian/html/detail.html";


document.getElementsByClassName('box1Rotation')[0].innerHTML = getImgItem(data.Rotation);
prev = document.getElementsByClassName("prev")[0];
next = document.getElementsByClassName("next")[0];

function getImgItem(RotationImg) {
    let ImgItem = '';
    RotationImg.forEach(function (item, index) {
        if (index < 5) {
            ImgItem += `<div class="Rotation" ><img src="${item.imgSrc}" ></div>`
        }
    });
    return ImgItem;
}

function slide() {
    timer = setInterval(function () {
        num++;
        if (num >= 5) {
            num = 0;
        }
// 			console.log(index)
        // 切换图片
        changeImg(num);
    }, 1000);
}

function slideImg() {
    changeImg(num);
    slide();

    for (let i = 0; i < 5; i++) {
        // dots[i].id=i;
        dots[i].onclick = () => {
            num = i;
            changeImg(i);
            clearInterval(timer);
            slide();
        }

    }
}

slideImg();

next.onclick = function () {
    num++;
    if (num >= 5) num = 0;
    changeImg(num);
    clearInterval(timer);
    slide();
}
prev.onclick = function () {
    num--;
    if (num < 0) num = 4;
    changeImg(num);
    clearInterval(timer);
    slide();
}

function changeImg(num) {
    for (let i = 0; i < 5; i++) {
        pics[i].style.display = "none";
        dots[i].style.boxShadow = "none";
        // pics[num].className="RotationImg";
    }
    // console.log(num);
    pics[num].style.display = "block";
    // console.log(pics[num].className);
    dots[num].style.boxShadow = "3px 3px 10px #909090"

}


// 新闻动态----------------------------------------

document.getElementsByClassName('news')[0].innerHTML =
    `<div class="dynamic">
        <img src='${data.newsList.img}'>
        <div class="dynamicItem">
        <div class="dynamicDate">
        <div class="dynamicDateDetail">${data.newsList.list.date.day}</div>
        <div class="dynamicDateDetailNext">${data.newsList.list.date.year}</div>
    </div>
    <div class="dynamicDateBox">
        <div class="dynamicDateTitle">${data.newsList.list.title}</div>
        <span class="dynamicDateContentDetail">${data.newsList.list.content}</span>
    </div>
    </div>
</div>
<div class="dynamicRight">
</div>
 `;

document.getElementsByClassName('dynamicRight')[0].innerHTML = getNewsList(data.newsList.listItem);

function getNewsList(data) {
    let newsList = ``;
    // console.log(data);
    data.forEach(function (item, index) {
        if (index < 3) {
            newsList += `
           <div class="newsRight" >
                    <div class="dynamicDate">
                    <div class="dynamicDateDetail ">${item.date.day}</div>
                    <div class="dynamicDateDetailNext">${item.date.year}</div>
                    </div>
                <div class="dynamicDateBox dynamicDateBoxRight">
                    <div class="dynamicDateTitle">${item.title}</div>
                    <span class="dynamicDateContentDetail">${item.content}</span>
                </div>
            </div>
         `
        }
    });
    return newsList;
}


// 权威支持----------------------------------------


document.getElementsByClassName('supportList')[0].innerHTML = getSupportList(data.supportList);

function getSupportList(data) {
    let supportList = ``;
    data.forEach(function (item, i) {
        if (i < 3) {
            supportList += `
            <div class="supportListItem">
                <div class="supportListItemImg"><img src='${item.imgSrc}'></div>
                 <div class="supportContent">
                   <div class="supportTitle">${item.title}</div>
                        <div class="supportSolid"></div>
                        <span class="supportDetail">${item.content}</span>
                </div>
            </div>
            `
        }
    });
    return supportList;
};








